// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   FtpServerServlet.java

package org.baixin.ftp.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.ftpserver.FtpServer;

public class FtpServerServlet extends HttpServlet
{

	private static final long serialVersionUID = 0x4ce0c3c3daf114c9L;

	public FtpServerServlet()
	{
	}

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException
	{
		FtpServer server = (FtpServer)getServletContext().getAttribute("org.apache.ftpserver");
		PrintWriter wr = resp.getWriter();
		wr.print("<html>");
		wr.print("<head>");
		wr.print("<title>FtpServer status servlet</title>");
		wr.print("</head>");
		wr.print("<body>");
		wr.print("<form method='post'>");
		if (server.isStopped())
			wr.print("<p>FtpServer is stopped.</p>");
		else
		if (server.isSuspended())
		{
			wr.print("<p>FtpServer is suspended.</p>");
			wr.print("<p><input type='submit' name='resume' value='Resume'></p>");
			wr.print("<p><input type='submit' name='stop' value='Stop'></p>");
		} else
		{
			wr.print("<p>FtpServer is running.</p>");
			wr.print("<p><input type='submit' name='suspend' value='Suspend'></p>");
			wr.print("<p><input type='submit' name='stop' value='Stop'></p>");
		}
		wr.print("</form>");
		wr.print("</body>");
		wr.print("</html>");
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException
	{
		FtpServer server = (FtpServer)getServletContext().getAttribute("org.apache.ftpserver");
		if (req.getParameter("stop") != null)
			server.stop();
		else
		if (req.getParameter("resume") != null)
			server.resume();
		else
		if (req.getParameter("suspend") != null)
			server.suspend();
		resp.sendRedirect("/ftpserver");
	}
}
